package com.orange.score.activity.index;

import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;
import com.orange.score.activity.common.CommonFootballActivity;
import com.orange.score.app.ScoreApplication;
import com.orange.score.model.index.Company;
import com.orange.score.model.index.CompanyManager;
import com.orange.score.model.index.OddsManager;
import com.orange.score.model.index.OddsType;
import com.orange.score.service.IndexService;
import com.orange.score.utils.ToastUtil;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class SelectCompanyActivity extends CommonFootballActivity
{
  public static final int ACTION_SELECT_COMPANY = 20120217;
  private static int DEFAULT_COLUMN = 0;
  private static int DEFAULT_SELECTED_COUNT = 0;
  public static final String KEY_SELECTED_COMPANY = "selectedCompanyId";
  public static final String KEY_SELECTED_ODDS = "selectedOdds";
  public static final String TAG = "CompanySelectActivity";
  private Button[] buttons;
  private Button cancelButton;
  private CompanyManager companyManager;
  private Button daxiaoButton;
  private OddsManager indexManager;
  private Button okButton;
  private Button oupeiButton;
  private Set<Company> selectedSet = new HashSet();
  private TableLayout tableLayout;
  private Button yapeiButton;

  private void buildTableLayout(List<Company> paramList, int paramInt)
  {
    int j;
    int k;
    TableRow localTableRow;
    TableRow.LayoutParams localLayoutParams;
    int l;
    if (paramList == null)
      return;
    int i = paramList.size();
    if (i % DEFAULT_COLUMN == 0)
      j = i / DEFAULT_COLUMN;
    while (true)
    {
      this.buttons = new Button[j * DEFAULT_COLUMN];
      k = 0;
      while (true)
      {
        if (k >= j);
        localTableRow = new TableRow(this);
        localLayoutParams = new TableRow.LayoutParams(-2, -2, 1F);
        localLayoutParams.width = 1;
        localLayoutParams.setMargins(15, 15, 15, 15);
        this.tableLayout.setLayoutParams(localLayoutParams);
        l = 0;
        if (l < paramInt)
          break label138;
        this.tableLayout.addView(localTableRow);
        ++k;
      }
      j = 1 + i / DEFAULT_COLUMN;
    }
    label138: int i1 = l + k * DEFAULT_COLUMN;
    this.buttons[i1] = new Button(this);
    if (i1 >= i)
    {
      this.buttons[i1].setLayoutParams(localLayoutParams);
      localTableRow.addView(this.buttons[i1]);
      this.buttons[i1].setVisibility(4);
    }
    while (true)
    {
      Company localCompany;
      do
        while (true)
        {
          do
            while (true)
            {
              do
                while (true)
                {
                  while (true)
                    ++l;
                  localCompany = (Company)paramList.get(i1);
                  this.buttons[i1].setText(localCompany.getCompanyName());
                  this.buttons[i1].setLayoutParams(localLayoutParams);
                  this.buttons[i1].setSingleLine();
                  this.buttons[i1].setTextSize(12.0F);
                  this.buttons[i1].setBackgroundResource(2130837640);
                  this.buttons[i1].setHeight(33);
                  localTableRow.addView(this.buttons[i1]);
                  setCompanySelectedButtonClickListener(this.buttons[i1], localCompany);
                  switch ($SWITCH_TABLE$com$orange$score$model$index$OddsType()[this.companyManager.getOddsType().ordinal()])
                  {
                  default:
                  case 1:
                  case 3:
                  case 2:
                  }
                }
              while (!(this.companyManager.getYapeiSelectedSet().contains(localCompany)));
              this.buttons[i1].performClick();
            }
          while (!(this.companyManager.getOupeiSelectedSet().contains(localCompany)));
          this.buttons[i1].performClick();
        }
      while (!(this.companyManager.getDaxiaoSelectedSet().contains(localCompany)));
      this.buttons[i1].performClick();
    }
  }

  private CompanyManager getCompanyManager()
  {
    return getIndexService().getCompanyManager();
  }

  private OddsManager getIndexManager()
  {
    return getIndexService().getOddsManager();
  }

  private IndexService getIndexService()
  {
    return ((ScoreApplication)getApplication()).getIndexService();
  }

  private ArrayList<String> getSelectedCompanyIdArray()
  {
    ArrayList localArrayList = new ArrayList();
    Object[] arrayOfObject = this.selectedSet.toArray();
    int i = 0;
    while (true)
    {
      if (i >= arrayOfObject.length)
        return localArrayList;
      localArrayList.add(((Company)arrayOfObject[i]).getCompanyId());
      ++i;
    }
  }

  private void initInputSelectedList()
  {
    switch ($SWITCH_TABLE$com$orange$score$model$index$OddsType()[this.companyManager.getOddsType().ordinal()])
    {
    default:
    case 1:
    case 3:
    case 2:
    }
    while (true)
    {
      while (true)
      {
        do
        {
          return;
          this.yapeiButton.setSelected(true);
          buildTableLayout(this.companyManager.getYapeiCompanyList(), DEFAULT_COLUMN);
        }
        while ((this.companyManager.getYapeiSelectedSet().size() != 0) || (this.buttons == null) || (this.buttons.length <= 0));
        int i = 0;
        while (true)
        {
          if (i >= DEFAULT_SELECTED_COUNT);
          this.buttons[i].performClick();
          ++i;
        }
        this.oupeiButton.setSelected(true);
        buildTableLayout(this.companyManager.getOupeiCompanyList(), DEFAULT_COLUMN);
      }
      this.daxiaoButton.setSelected(true);
      buildTableLayout(this.companyManager.getDaxiaoCompanyList(), DEFAULT_COLUMN);
    }
  }

  private void removeTableLayout()
  {
    this.tableLayout.removeAllViewsInLayout();
  }

  private void setCancelButtonClickListener()
  {
    this.cancelButton.setBackgroundResource(2130837638);
    this.cancelButton.setOnClickListener(new View.OnClickListener(this)
    {
      public void onClick()
      {
        this.this$0.finish();
      }
    });
  }

  private void setCompanySelectedButtonClickListener(Button paramButton, Company paramCompany)
  {
    paramButton.setOnClickListener(new View.OnClickListener(this, paramButton, paramCompany)
    {
      public void onClick()
      {
        Button localButton;
        boolean bool;
        if (this.val$button.isSelected())
        {
          SelectCompanyActivity.access$1(this.this$0).remove(this.val$company);
          switch ($SWITCH_TABLE$com$orange$score$model$index$OddsType()[SelectCompanyActivity.access$3(this.this$0).getOddsType().ordinal()])
          {
          default:
            localButton = this.val$button;
            if (!(this.val$button.isSelected()))
              break label352;
            bool = false;
          case 1:
          case 3:
          case 2:
          }
        }
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  localButton.setSelected(bool);
                  SelectCompanyActivity.access$9(this.this$0);
                  while (true)
                  {
                    while (true)
                    {
                      while (true)
                      {
                        while (true)
                        {
                          return;
                          SelectCompanyActivity.access$3(this.this$0).getYapeiSelectedSet().remove(this.val$company);
                        }
                        SelectCompanyActivity.access$3(this.this$0).getOupeiSelectedSet().remove(this.val$company);
                      }
                      SelectCompanyActivity.access$3(this.this$0).getDaxiaoSelectedSet().remove(this.val$company);
                    }
                    if ((SelectCompanyActivity.access$1(this.this$0) == null) || (SelectCompanyActivity.access$1(this.this$0).size() != SelectCompanyActivity.access$8()))
                      break;
                    ToastUtil.showMessage(this.this$0.getApplicationContext(), "最多只能选择四个");
                  }
                  SelectCompanyActivity.access$1(this.this$0).add(this.val$company);
                  switch ($SWITCH_TABLE$com$orange$score$model$index$OddsType()[SelectCompanyActivity.access$3(this.this$0).getOddsType().ordinal()])
                  {
                  default:
                  case 1:
                  case 3:
                  case 2:
                  }
                }
                SelectCompanyActivity.access$3(this.this$0).getYapeiSelectedSet().add(this.val$company);
              }
              SelectCompanyActivity.access$3(this.this$0).getOupeiSelectedSet().add(this.val$company);
            }
            SelectCompanyActivity.access$3(this.this$0).getDaxiaoSelectedSet().add(this.val$company);
          }
          label352: bool = true;
        }
      }
    });
  }

  private void setOddsFilterButtonClickListener(int paramInt, OddsType paramOddsType)
  {
    ((Button)findViewById(paramInt)).setOnClickListener(new View.OnClickListener(this, paramOddsType, paramInt)
    {
      public void onClick()
      {
        SelectCompanyActivity.access$3(this.this$0).setOddsType(this.val$oddsType);
        SelectCompanyActivity.access$4(this.this$0, this.val$buttonId);
        SelectCompanyActivity.access$5(this.this$0);
        SelectCompanyActivity.access$1(this.this$0).clear();
        switch (this.val$buttonId)
        {
        default:
        case 2131558542:
        case 2131558543:
        case 2131558544:
        }
        while (true)
        {
          while (true)
          {
            while (true)
            {
              return;
              SelectCompanyActivity.access$7(this.this$0, SelectCompanyActivity.access$3(this.this$0).getYapeiCompanyList(), SelectCompanyActivity.access$6());
            }
            SelectCompanyActivity.access$7(this.this$0, SelectCompanyActivity.access$3(this.this$0).getOupeiCompanyList(), SelectCompanyActivity.access$6());
          }
          SelectCompanyActivity.access$7(this.this$0, SelectCompanyActivity.access$3(this.this$0).getDaxiaoCompanyList(), SelectCompanyActivity.access$6());
        }
      }
    });
  }

  private void setOkButtonClickListener()
  {
    this.okButton.setBackgroundResource(2130837638);
    2 local2 = new View.OnClickListener(this)
    {
      public void onClick()
      {
        if ((SelectCompanyActivity.access$1(this.this$0) == null) || (SelectCompanyActivity.access$1(this.this$0).size() == 0))
          ToastUtil.showMessage(this.this$0.getApplicationContext(), "至少选择一间赔率公司");
        while (true)
        {
          return;
          Intent localIntent = new Intent();
          ArrayList localArrayList = SelectCompanyActivity.access$2(this.this$0);
          Log.d("CompanySelectActivity", "selectedCompany=" + localArrayList.toString());
          Bundle localBundle = new Bundle();
          localBundle.putStringArrayList("selectedCompanyId", localArrayList);
          localIntent.putExtras(localBundle);
          this.this$0.setResult(20120217, localIntent);
          this.this$0.finish();
        }
      }
    };
    this.okButton.setOnClickListener(local2);
  }

  private void updateButtonTextColor()
  {
    Button localButton;
    Button[] arrayOfButton = this.buttons;
    int i = arrayOfButton.length;
    int j = 0;
    if (j >= i);
    do
    {
      return;
      localButton = arrayOfButton[j];
    }
    while (localButton == null);
    if (localButton.isSelected())
      localButton.setTextColor(getResources().getColor(2131230751));
    while (true)
    {
      while (true)
        ++j;
      localButton.setTextColor(-16777216);
    }
  }

  private void updateOddsFilterButton(int paramInt)
  {
    int[] arrayOfInt = new int[3];
    arrayOfInt[0] = 2131558542;
    arrayOfInt[1] = 2131558543;
    arrayOfInt[2] = 2131558544;
    int i = 0;
    if (i >= arrayOfInt.length)
      return;
    Button localButton = (Button)findViewById(arrayOfInt[i]);
    if (arrayOfInt[i] == paramInt)
      localButton.setSelected(true);
    while (true)
    {
      while (true)
        ++i;
      localButton.setSelected(false);
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    setContentView(2130903087);
    this.indexManager = getIndexManager();
    this.companyManager = getCompanyManager();
    this.yapeiButton = ((Button)findViewById(2131558542));
    this.oupeiButton = ((Button)findViewById(2131558543));
    this.daxiaoButton = ((Button)findViewById(2131558544));
    this.okButton = ((Button)findViewById(2131558552));
    this.cancelButton = ((Button)findViewById(2131558553));
    this.tableLayout = ((TableLayout)findViewById(2131558548));
    this.tableLayout.setStretchAllColumns(true);
    this.tableLayout = ((TableLayout)findViewById(2131558548));
    this.tableLayout.setStretchAllColumns(true);
    initInputSelectedList();
    setOddsFilterButtonClickListener(2131558542, OddsType.YAPEI);
    setOddsFilterButtonClickListener(2131558543, OddsType.OUPEI);
    setOddsFilterButtonClickListener(2131558544, OddsType.DAXIAO);
    setOkButtonClickListener();
    setCancelButtonClickListener();
  }

  protected void onPause()
  {
    super.onPause();
    ScoreApplication.currentActivity = null;
  }

  protected void onResume()
  {
    super.onResume();
    ScoreApplication.currentActivity = this;
  }
}